/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package android.entidades;

import android.app.ContextoAndroid;
import android.app.Mensaje;
import android.content.Context;
import android.content.ContextWrapper;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.InputStreamReader;

/**
 *
 * @author payo
 */
public class DataLocal {
    public static String id="";
    private static String path = "";
    private static String userFile = "datalocal.txt";
    
    public static String getDataLocal()
    {
        ContextWrapper cw = new ContextWrapper(ContextoAndroid.context);
        File directory = cw.getDir("media", Context.MODE_PRIVATE);
        path = directory.getAbsolutePath()+"/"+userFile;
        try {
            File myFile = new File(path);
            FileInputStream fIn = new FileInputStream(myFile);
            BufferedReader myReader = new BufferedReader(new InputStreamReader(fIn));
            String aDataRow = "";
            String aBuffer = "";
            while ((aDataRow = myReader.readLine()) != null) {
                    aBuffer += aDataRow;
            }
            myReader.close();
            return aBuffer;
        } 
        catch (Exception e) {
            return "0";
        }
    }
    
    public static void saveDataLocal(String voz) 
    {
        ContextWrapper cw = new ContextWrapper(ContextoAndroid.context);
        File directory = cw.getDir("media", Context.MODE_PRIVATE);
        try
        {
            path = directory.getAbsolutePath()+"/"+userFile;
            FileWriter logWriter = new FileWriter(path);                  
            BufferedWriter out = new BufferedWriter(logWriter); 
            out.write(voz);
            out.close();
            } 
        catch (Exception e) {
          Mensaje.Mostrar(e.toString());
        }
    }
    
    public static void deleteDataLocal() 
    {
        ContextWrapper cw = new ContextWrapper(ContextoAndroid.context);
        File directory = cw.getDir("media", Context.MODE_PRIVATE);
        try
        {
            path = directory.getAbsolutePath()+"/"+userFile;
            File myFile = new File(path);
            myFile.delete();
            id = "";
        } 
        catch (Exception e) {
          Mensaje.Mostrar(e.toString());
        }
    }
}
